/*********************
* Author:Dzlua
* QQ:505544956
* time:2016/12/03
*/
#include "LuaSlider.h"
#include "../../utilities/Log.h"

#ifdef EDUI_USE_LUAPLUS

EDUI_NAMESPACE_BEGIN

#define CObjPtr (Slider::ToSlider(m_cobj))

void* LuaSlider::GetInterface(void* data)
{
    if (!data) return 0;
    LuaSlider* slider = new LuaSlider((Slider*)data);
#ifdef EDUI_TEST_NEW_DELETE
    ++m_newdeleteNum;
    Log("[LuaSlider] new LuaSlider : %d, %d", slider, data);
#endif
    return slider;
}

void LuaSlider::Release()
{
#ifdef EDUI_TEST_NEW_DELETE
    --m_newdeleteNum;
    Log("[LuaSlider] delete LuaSlider : %d, %d, %s", this, m_cobj, this->GetName());
#endif
    delete this;
}

LuaSlider::LuaSlider(Slider* slider) : LuaProgress(slider)
{}

LuaSlider::~LuaSlider()
{}

//----------------------------------------//

bool LuaSlider::SetRect(int x, int y, int w, int h)
{
    Rect data(x, y, w, h);
    return CObjPtr->SetRect(&data);
}

void LuaSlider::SetThumbSize(int w, int h)
{
    CObjPtr->SetThumbSize(w, h);
}

int LuaSlider::GetThumbSize(LuaState *L)
{
    Size sz = CObjPtr->GetThumbSize();
    LuaObject obj = LuaBaseNS::ToLuaObj(L, &sz);
    obj.Push(L);
    return 1;
}

int LuaSlider::GetThumbRect(LuaState *L)
{
    Rect rc = CObjPtr->GetThumbRect();
    LuaObject obj = LuaBaseNS::ToLuaObj(L, &rc);
    obj.Push(L);
    return 1;
}

int LuaSlider::GetBarRect(LuaState *L)
{
    Rect rc = CObjPtr->GetBarRect();
    LuaObject obj = LuaBaseNS::ToLuaObj(L, &rc);
    obj.Push(L);
    return 1;
}

void LuaSlider::SetStep(int step)
{
    CObjPtr->SetStep(step);
}

int LuaSlider::GetStep()
{
    return CObjPtr->GetStep();
}

bool LuaSlider::SetValue(int val)
{
    return CObjPtr->SetValue(val);
}

//----------------------------------------//

void LuaSlider::Register(LuaState *L)
{
    LuaObject obj = LuaHelperNS::AddToMetas(L, "Slider", "Progress");
    obj.SetObject("__index", obj);
    obj.RegisterDirect("__NewCObj__", &LuaSlider::GetInterface);

    obj.RegisterObjectDirect("SetRect", (LuaSlider*)0, &LuaSlider::SetRect);
    obj.RegisterObjectDirect("SetThumbSize", (LuaSlider*)0, &LuaSlider::SetThumbSize);
    obj.RegisterObjectFunctor("GetThumbSize", &LuaSlider::GetThumbSize);
    obj.RegisterObjectFunctor("GetThumbRect", &LuaSlider::GetThumbRect);
    obj.RegisterObjectFunctor("GetBarRect", &LuaSlider::GetBarRect);
    obj.RegisterObjectDirect("SetStep", (LuaSlider*)0, &LuaSlider::SetStep);
    obj.RegisterObjectDirect("GetStep", (LuaSlider*)0, &LuaSlider::GetStep);
    obj.RegisterObjectDirect("SetValue", (LuaSlider*)0, &LuaSlider::SetValue);
}

#undef CObjPtr

EDUI_NAMESPACE_END

#endif